package com.ptszyxx.popose.module.main.mine.adapter;

import android.view.View;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder;
import com.ptszyxx.popose.R;
import com.ptszyxx.popose.databinding.ItemMineShopBinding;
import com.ptszyxx.popose.module.main.mine.vm.MineShopTabVM;
import com.ysg.http.data.entity.mine.ShopEntity;

public class MineShopAdapter extends BaseQuickAdapter<ShopEntity, BaseDataBindingHolder<ItemMineShopBinding>> {

    private MineShopTabVM viewModel;
    private Presenter mPresenter = new Presenter();
    private int currentPosition;

    public MineShopAdapter(MineShopTabVM viewModel) {
        super(R.layout.item_mine_shop);
        this.viewModel = viewModel;
    }

    public void setCurrentPosition(int position){
        this.currentPosition = position;
        notifyDataSetChanged();
    }


    @Override
    protected void convert(BaseDataBindingHolder<ItemMineShopBinding> holder, ShopEntity item) {
        ItemMineShopBinding binding = holder.getDataBinding();
        if (binding != null) {
            binding.setEntity(item);
            binding.setViewModel(viewModel);
            binding.setPresenter(mPresenter);
            binding.setPosition(holder.getBindingAdapterPosition());
            binding.executePendingBindings();

            int position = holder.getBindingAdapterPosition();
            if (currentPosition == position) {
                binding.rlItemAll.setBackgroundResource(R.drawable.shop_select);
                binding.ivItemXZ.setVisibility(View.VISIBLE);
            } else {
                binding.rlItemAll.setBackgroundResource(R.drawable.shape_shop_unselect);
                binding.ivItemXZ.setVisibility(View.GONE);
            }
        }
    }

    public static class Presenter{
        public void onItemClick(MineShopTabVM viewModel, ShopEntity entity, int position){
            viewModel.onItemClick(entity, position);
        }
    }







}
